package com.roncoo.education.course.service.api.pc;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.education.course.common.req.*;
import com.roncoo.education.course.service.api.pc.biz.PcApiCourseTopIcBiz;
import com.roncoo.education.course.service.api.pc.biz.PcApiTopIcAnswerBiz;
import com.roncoo.education.course.service.api.pc.biz.PcApiTopIcBiz;
import com.roncoo.education.course.service.api.pc.biz.PcApiTopIcHistoryBiz;
import com.roncoo.education.course.service.dao.impl.mapper.entity.CourseTopic;
import com.roncoo.education.util.annotation.RequestRequire;
import com.roncoo.education.util.base.BaseController;
import com.roncoo.education.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * 测试 问卷 题目管理器
 *
 */
@RestController
@RequestMapping(value = "/course/pc/course/topic")
@Api(description = "测试 问卷 题目管理器")
public class PcApiCourseTopIcController extends BaseController {

	@Autowired
	private PcApiCourseTopIcBiz biz;

	@Autowired
    private PcApiTopIcBiz topIcBiz;

	@Autowired
	private PcApiTopIcAnswerBiz answerBiz;

	@Autowired
	private PcApiTopIcHistoryBiz historyBiz;

	/**
	 * 分页返回问卷列表
	 *
	 * @param
	 * @return
	 */
	@ApiOperation(value = "问卷or试卷分页列表 type :1 问卷 2 测试", notes = "问卷或者测试分页列表")
	@RequestMapping(value = "/test/list", method = RequestMethod.POST)
	public Result<Page> list(@RequestBody CourseTopicREQ courseTopicREQ) {


		return biz.findPageList(courseTopicREQ);
	}

	@ApiOperation(value = "保存或者修改试卷", notes = "保存或者修改 问卷 测试")
	@RequestMapping(value = "/test/saveOrUpdate", method = RequestMethod.POST)
	@RequestRequire(require = "title,type,descript",parameter =CourseTopicREQ.class )
	public Result saveOrModify(@RequestBody CourseTopicREQ courseTopicREQ){
  		return biz.saveOrmodefy(courseTopicREQ);
	}



	@ApiOperation(value = "删除试卷", notes = "删除试卷")
	@RequestMapping(value = "/test/del", method = RequestMethod.POST)
	@RequestRequire(require = "id",parameter =CourseTopicREQ.class )
	public Result del(@RequestBody CourseTopicREQ courseTopicREQ){
		return biz.delete(courseTopicREQ);
	}



    /**
     * 分页返回题目列表
     *
     * @param
     * @return
     */
    @ApiOperation(value = "根据考卷Id 返回题目列表", notes = "根据考卷Id 返回题目列表" )
    @RequestMapping(value = "/list", method = RequestMethod.POST)
	@RequestRequire(require = "courseTopicId",parameter = TopicREQ.class)
    public Result<Page> topicList(@RequestBody TopicREQ topicREQ) {


        return topIcBiz.findPageList(topicREQ);
    }

    /**
     * 保存或者修改 题目
     *
     * @param
     * @return
     */
    @ApiOperation(value = "保存或修改题目", notes = "保存或修改题目" )
    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
	@RequestRequire(require = "courseTopicId,title,topic",parameter = TopicREQ.class)
    public Result saveOrUpdate(@RequestBody TopicREQ topicREQ) {


        return topIcBiz.saveOrUpdate(topicREQ);
    }

	/**
	 * 删除题目
	 *
	 * @param
	 * @return
	 */
	@ApiOperation(value = "删除题目", notes = "题目删除" )
	@RequestMapping(value = "/del", method = RequestMethod.POST)
	public Result del(@RequestBody TopicREQ topicREQ) {


		return topIcBiz.del(topicREQ);
	}

	/**
	 * 分页返回参与问卷 人数
	 *
	 * @param
	 * @return
	 */
	@ApiOperation(value = "分页返回参与问卷 人数", notes = "分页返回参与问卷 人数" )
	@RequestMapping(value = "/totalCount", method = RequestMethod.POST)
	public Result<Page> totalCount(@RequestBody AnswerREQ answerREQ) {

		return answerBiz.findPageList(answerREQ);
	}


    /**
     * 问卷选项统计
     *
     * @param
     * @return
     */
    @ApiOperation(value = "问卷选项统计", notes = "问卷选项统计" )
    @RequestMapping(value = "/count/answer", method = RequestMethod.POST)
	@RequestRequire(require = "courseTopicId",parameter = AnswerREQ.class)
    public Result<Page> countAnswer(@RequestBody AnswerREQ answerREQ) {

        return answerBiz.countAnswer(answerREQ);
    }


	/**
	 * 分页返回历史考试记录
	 *
	 * @param
	 * @return
	 */
	@ApiOperation(value = "分页返回历史考试记录", notes = "分页返回历史考试记录" )
	@RequestMapping(value = "/test/records", method = RequestMethod.POST)
	public Result<Page> testRecords(@RequestBody TopicHistoryREQ recordsREQ) {

		return historyBiz.findPageList(recordsREQ);
	}





	@ApiOperation(value = "修改标题", notes = "修改标题")
	@RequestMapping(value = "/test/update", method = RequestMethod.POST)
	@RequestRequire(require = "id",parameter =CourseTopicREQ.class )
	public Result updateName(@RequestBody CourseTopicREQ courseTopicREQ){
		return biz.update(courseTopicREQ);
	}

	@ApiOperation(value = "编辑", notes = "编辑")
	@RequestMapping(value = "/test/updateall", method = RequestMethod.POST)
	@RequestRequire(require = "id",parameter =CourseTopicREQ.class )
	public Result updateAll(@RequestBody CourseTopicREQ courseTopicREQ){
		return biz.updateAll(courseTopicREQ);
	}

	/**
	 * 跳转编辑页面
	 * @param courseTopicREQ
	 * @return
	 */
	@RequestMapping(value = "/test/updatelist", method = RequestMethod.POST)
	@RequestRequire(require = "id",parameter =CourseTopicREQ.class )
	public Result updateList(@RequestBody CourseTopicREQ courseTopicREQ){
		return biz.updateList(courseTopicREQ);
	}



}
